package com.etogc.groupchat.group.ui;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.etogc.groupchat.R;
import com.etogc.groupchat.group.adpt.MyGroupAdapter;
import com.etogc.groupchat.group.biz.GroupHttpBiz;
import com.etogc.util.IntentHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 收藏的群
 */
public class FavGroupActivity extends AppCompatActivity {

    private RecyclerView lvMyGroup;
    private MyGroupAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fav_group);
        lvMyGroup = findViewById(R.id.lvFavGroup);
        findViewById(R.id.ivBack).setVisibility(View.VISIBLE);
        findViewById(R.id.ivBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                IntentHelper.finish(FavGroupActivity.this);
            }
        });
        ((TextView) findViewById(R.id.tvTitle)).setText("我的收藏");
        adapter = new MyGroupAdapter(this);
//        initData();
        initView();
//        initData();
    }

    @Override
    protected void onResume() {
        requestList();
        super.onResume();
    }

    private void initData() {
        List<HashMap<String, String>> list = new ArrayList<>();
        HashMap<String, String> map = new HashMap<>();
        map.put("groupName", "789");
        map.put("inviteCode", "3212");
        map.put("groupID", "789");
        HashMap<String, String> map2 = new HashMap<>();
        map2.put("groupName", "890");
        map2.put("inviteCode", "3212");
        map2.put("groupID", "890");
        list.add(map);
        list.add(map2);
        adapter.setData(list);
    }

    private void requestList() {
        GroupHttpBiz.getFavGroup(this, adapter);
    }

    private void initView() {
        lvMyGroup.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        lvMyGroup.setAdapter(adapter);
        lvMyGroup.addItemDecoration(new RecyclerView.ItemDecoration() {
        });
    }
}
